package ink.unit;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;

/**
 * @author wangzhuangzhuang
 * @DESC:
 * @date 2022-01-25 13:24
 */
public class CommonUtil {
	public static void main(String[] args) {

//		test02(); // 26
		test03(); //

	}

	private static void test01(){
		int abs = Math.abs(-100);
		System.out.println("abs: " + abs); // abs: 100

		double abs1 = Math.abs(-7.8);
		System.out.println("abs1: " + abs1); // abs1: 7.8

		int max = Math.max(100, 99);
		System.out.println("max: " + max); // max: 100

		double min = Math.min(1.2, 2.3);
		System.out.println("min: " + min); // min: 1.2

		double pow = Math.pow(2, 10);
		System.out.println("pow: " + pow); // pow: 1024.0

		double sqrt = Math.sqrt(2);
		System.out.println("sqrt: " + sqrt); // sqrt: 1.4142135623730951

		double exp = Math.exp(2);
		System.out.println("exp: " + sqrt); // exp: 1.4142135623730951

	}

	private static void test02(){
		double r = Math.random();// x的范围是[0,1)
		double min = 10;
		double max = 50;
		double y = r * (max - min) + min; // y的范围是[10,50)
		long n = (long)y; // n的范围是[10,50)的整数
		System.out.println("y: " + y);
		System.out.println("n: " + n);
	}

	private static void test03(){
		SecureRandom sr = null; // 生成安全的随机数
		try{
			sr = SecureRandom.getInstanceStrong(); // 获取高强度安全随机数生成器
		} catch (NoSuchAlgorithmException e) {
			sr = new SecureRandom(); // 获取普通的安全随机数生成器
		}
		byte[] buffer = new byte[16];
		sr.nextBytes(buffer); // 用安全随机数填充buffer
		System.out.println(Arrays.toString(buffer));
	}

}